<?php 

$auth = $_SESSION['auth'];
if (empty($auth)) die('用户未登录！');

global $config;
if (!in_array($auth['id'], $config['manager']) && $city_info['user_id'] != $auth['id']) die('用户权限不够!^_^');


if (empty($_GET)) die;

$page = @intval($_GET['page']);

if (empty($page)) { $page = 1; }
$limit = 20;

$cond = "WHERE city = $forum_city";

$carousels = dt_query("SELECT * FROM forum_carousel $cond ORDER BY m_at DESC LIMIT ".$limit * ($page - 1).",$limit");
if (!$carousels) die('获取carousel数据失败！^_^');

?>
<div class="container">
	<div class="row clearfix">
		<ol class="breadcrumb forum-breadcrumb">
			<li><a href="?c=forum"><span class="glyphicon glyphicon-home"></span> 首页</a></li>
			<li class="active"><span class="glyphicon glyphicon-edit"></span> 滚动图管理</li>
		</ol>
	</div>
</div>
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<a class="btn btn-success pull-right" href="?c=forum&a=forum_carousel_add">添加图片</a>
			<table class="table">
				<thead>
					<tr>
						<th>图片</th>
						<th>链接URL</th>
						<th>设置时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				<?php while($carousel = mysql_fetch_array($carousels)) { ?>
				<tr id="<?php echo $carousel['id'] ?>">
					<td><img src="<?php echo $carousel['img_url'] ?>" height="50px"></td>
					<td><?php echo $carousel['img_link'] ?></td>
					<td><?php echo fmt_date($carousel['c_at']) ?></td>
					<td>
						<a class="btn btn-default btn-sm" href="?c=forum&a=forum_carousel_edit&carousel_id=<?php echo $carousel['id'] ?>">设置</a>
						<a class="btn btn-default btn-sm" href="javascript:do_forum_carousel_del(<?php echo $carousel['id'] ?>)">删除</a>
					</td>
				</tr>
				<?php } ?>
				</tbody>
			</table>

			<?php pagination('forum_carousel', $cond, $page, $limit, '?c=forum&a=forum_carousel_manage&page=') ?>
		</div>


	</div>
</div>
<script type="text/javascript">

$(document).ready(function(){
	$('li#forum_manage').addClass('active');
});

function do_forum_carousel_del(carousel_id) {
	if (!confirm (" O_O 确定要删除吗！")) return;

	$.get('?c=forum&a=do_forum_carousel_opr&opr=1&carousel_id='+carousel_id, function(rs){
		if ('s0' != rs) { 
			alert(rs);
			return;
		}
		$('tr#'+carousel_id).remove();
	});
}
</script>
